import { BaseViteConfig } from '@ac/vite-config';
import { defineConfig, loadEnv, mergeConfig } from 'vite';
import { name } from './package.json';

import { viteExternalsPlugin } from 'vite-plugin-externals';
import qiankun from 'vite-plugin-qiankun';

export default ({ mode }: any) => {
	const env = loadEnv(mode, process.cwd());
	console.log(name, env);
	return defineConfig(
		mergeConfig(BaseViteConfig(__dirname), {
			plugins: [
				qiankun(name, { useDevMode: true }),
				viteExternalsPlugin({
					react: 'React',
					'react-dom': 'ReactDOM'
				})
			],
			server: {
				port: 7090,
				host: '0.0.0.0',
				cors: true,
				open: false
			}
		})
	);
};
